package com.ruoyi.agent.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.agent.mapper.KwMachineAgentMapper;
import com.ruoyi.agent.domain.KwMachineAgent;
import com.ruoyi.agent.service.IKwMachineAgentService;
import org.springframework.util.CollectionUtils;

/**
 * 主机运行AgentService业务层处理
 * 
 * @author gonianer
 * @date 2023-11-20
 */
@Service
public class KwMachineAgentServiceImpl implements IKwMachineAgentService 
{
    @Autowired
    private KwMachineAgentMapper kwMachineAgentMapper;

    /**
     * 查询主机运行Agent
     * 
     * @param id 主机运行Agent主键
     * @return 主机运行Agent
     */
    @Override
    public KwMachineAgent selectKwMachineAgentById(Long id)
    {
        return kwMachineAgentMapper.selectKwMachineAgentById(id);
    }

    /**
     * 查询主机运行Agent列表
     * 
     * @param kwMachineAgent 主机运行Agent
     * @return 主机运行Agent
     */
    @Override
    public List<KwMachineAgent> selectKwMachineAgentList(KwMachineAgent kwMachineAgent)
    {
        return kwMachineAgentMapper.selectKwMachineAgentList(kwMachineAgent);
    }

    @Override
    public KwMachineAgent selectKwMachineAgent(Long machineId) {
        KwMachineAgent agent = new KwMachineAgent();
        agent.setMachineId(machineId);
        List<KwMachineAgent> agents = this.selectKwMachineAgentList(agent);
        return CollectionUtils.isEmpty(agents)?null:agents.get(0);
    }

    /**
     * 新增主机运行Agent
     * 
     * @param kwMachineAgent 主机运行Agent
     * @return 结果
     */
    @Override
    public int insertKwMachineAgent(KwMachineAgent kwMachineAgent)
    {
        kwMachineAgent.setCreateTime(DateUtils.getNowDate());
        return kwMachineAgentMapper.insertKwMachineAgent(kwMachineAgent);
    }

    /**
     * 修改主机运行Agent
     * 
     * @param kwMachineAgent 主机运行Agent
     * @return 结果
     */
    @Override
    public int updateKwMachineAgent(KwMachineAgent kwMachineAgent)
    {
        kwMachineAgent.setUpdateTime(DateUtils.getNowDate());
        return kwMachineAgentMapper.updateKwMachineAgent(kwMachineAgent);
    }

    /**
     * 批量删除主机运行Agent
     * 
     * @param ids 需要删除的主机运行Agent主键
     * @return 结果
     */
    @Override
    public int deleteKwMachineAgentByIds(Long[] ids)
    {
        return kwMachineAgentMapper.deleteKwMachineAgentByIds(ids);
    }

    /**
     * 删除主机运行Agent信息
     * 
     * @param id 主机运行Agent主键
     * @return 结果
     */
    @Override
    public int deleteKwMachineAgentById(Long id)
    {
        return kwMachineAgentMapper.deleteKwMachineAgentById(id);
    }
}
